﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Windows;
using BrainTechLLC;
using BrainTechLLC.WPF;

namespace EventWindowHandler.Plugin
{
    public class EventInfoWindowHandler : WindowHandlerBase<EventInfoWindow, Window>, IEventInfoWindowHandler
    {
        public static PluginDefinitionLoaded<IEventInfoWindowHandler> Handler;

        public EventInfoWindowHandler(Window parentWindow, PluginDefinitionLoaded<IEventInfoWindowHandler> handler)
            : base(parentWindow)
        {
            Handler = handler;
            _parentWindow = parentWindow;
        }

        public void OpenEventInfoWindow(object owner)
        {            
            OpenWindow(owner as Window);
        }

        public bool IsOpen
        {
            get { return _window != null; }
        }

        public override void OpenWindow(Window owner)
        {
            if (_window == null)
            {
                _window = new EventInfoWindow() { Owner = owner as Window };
                _window.Closed += new EventHandler(_window_Closed);
                _window.RecordedEventInfoViewModel = new RecordedEventInfoViewModel(RecordedEventInfo.Instance);
                _window.Show();
            }

            _window.Show();
            _window.Focus();
        }

        private void _window_Closed(object sender, EventArgs e)
        {            
            _window.Closed -= _window_Closed;
            _window = null;
            OnPropertyChanged("IsOpen");
        }        
    }
}
